package com.swancloud.openstack.version.demon;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.swancloud.model.compute.Version;
import com.swancloud.model.compute.builder.VersionBuilder;
import com.swancloud.openstack.common.ListResult;

import java.util.List;
import java.util.Map;

/**
 * @Author 张立强 - zhangliqiang@asiacom.net.cn
 * @Description
 * @Date 2020-12-03 10:43
 **/
@JsonRootName("version")
@JsonIgnoreProperties(ignoreUnknown=true)
public class ApisVersion implements Version {

    private String id;

    private List<Map<String, String>> links;

    @JsonProperty("media-types")
    private List<Map<String, String>> mediaTypes;

    @JsonProperty("min_version")
    private String minVersion;

    @JsonProperty("max_version")
    private String maxVersion;

    private String status;

    private String updated;

    private String version;

    public static VersionBuilder builder() {
        return new ComputeVersionBuilder();
    }

    @Override
    public VersionBuilder toBuilder() {
        return new ComputeVersionBuilder(this);
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public List<Map<String, String>> getLinks() {
        return links;
    }

    @Override
    public List<Map<String, String>> getMediaTypes() {
        return mediaTypes;
    }

    @Override
    public String getMinVersion() {
        return minVersion;
    }

    @Override
    public String getMaxVersion() {
        return maxVersion;
    }

    @Override
    public Status getStatus() {
        return Version.Status.forValue(status);
    }

    @Override
    public String getUpdated() {
        return updated;
    }

    @Override
    public String getVersion() {
        return version;
    }

    public static class Versions extends ListResult<ApisVersion> {

        private static final long serialVersionUID = 1L;

        @JsonProperty("versions")
        List<ApisVersion> versions;

        @Override
        public List<ApisVersion> value() {
            return versions;
        }
    }

    public static class ComputeVersionBuilder implements VersionBuilder {

        private ApisVersion model;

        ComputeVersionBuilder() { this(new ApisVersion()); }

        ComputeVersionBuilder(ApisVersion version) {
            this.model = version;
        }

        @Override
        public VersionBuilder id(String id) {
            model.id = id;
            return this;
        }

        @Override
        public VersionBuilder links(List<Map<String, String>> links) {
            model.links = links;
            return this;
        }

        @Override
        public VersionBuilder mediaTypes(List<Map<String, String>> mediaTypes) {
            model.mediaTypes = mediaTypes;
            return this;
        }

        @Override
        public VersionBuilder minVersion(String minVersion) {
            model.minVersion = minVersion;
            return this;
        }

        @Override
        public VersionBuilder maxVersion(String maxVersion) {
            model.maxVersion = maxVersion;
            return this;
        }

        @Override
        public VersionBuilder status(String status) {
            model.status = status;
            return this;
        }

        @Override
        public VersionBuilder updated(String updated) {
            model.updated = updated;
            return this;
        }

        @Override
        public VersionBuilder version(String version) {
            model.version = version;
            return this;
        }

        @Override
        public Version build() {
            return model;
        }

        @Override
        public VersionBuilder from(Version in) {
            model = (ApisVersion) in;
            return this;
        }
    }
}
